﻿<UserControl x:Class="Samba.Modules.InventoryModule.RecipeView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Common="clr-namespace:Samba.Presentation.Common;assembly=Samba.Presentation.Common"
     mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0">
            <Label>
                <LocText ResourceIdentifierKey="RecipeName" Suffix=":"/>
            </Label>
            <TextBox HorizontalAlignment="Left" MinWidth="200" Text="{Binding Name,Mode=TwoWay}" />
            <Label>
                <LocText ResourceIdentifierKey="Product" Suffix=":"/>
            </Label>
            <ComboBox HorizontalAlignment="Left" MinWidth="200" SelectedItem="{Binding SelectedMenuItemName}"
                 ItemsSource="{Binding MenuItemNames}" IsEditable="True" />
            <Label>
                <LocText ResourceIdentifierKey="Portion" Suffix=":"/>
            </Label>
            <ComboBox HorizontalAlignment="Left" MinWidth="150" SelectedItem="{Binding Portion,Mode=TwoWay}"
                 DisplayMemberPath="Name" ItemsSource="{Binding SelectedMenuItem.Portions}">
            </ComboBox>
            <Label>
                <LocText ResourceIdentifierKey="FixedCost" Suffix=":"/>
            </Label>
            <Common:FilteredTextBox Type="Number" HorizontalAlignment="Left" MinWidth="100" TextAlignment="Right"
                 Text="{Binding FixedCost,Mode=TwoWay,StringFormat='#,#0.00'}" />
        </StackPanel>

        <GroupBox Grid.Row="1" Header="{LocText InventoryItems}"
                     Margin="5" Padding="5">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                <DataGrid ItemsSource="{Binding RecipeItems}" SelectedItem="{Binding SelectedRecipeItem, Mode=TwoWay}"
                             HorizontalAlignment="Left" GridLinesVisibility="None" RowHeaderWidth="0" Margin="0,3"
                             AutoGenerateColumns="False" CanUserSortColumns="False" CanUserDeleteRows="False" Background="{StaticResource {x:Static SystemColors.WindowBrushKey}}"
                             PreviewTextInput="DataGrid_PreviewTextInput" PreviewKeyDown="DataGrid_PreviewKeyDown"
                             PreparingCellForEdit="DataGrid_PreparingCellForEdit">
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Header="{LocText InventoryItemName}"
                                     MinWidth="100" CellStyle="{StaticResource LeftAlignedGridCell}">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Margin="3" Text="{Binding Name}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                            <DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <Grid FocusManager.FocusedElement="{Binding ElementName=cb}">
                                        <ComboBox Name="cb" IsEditable="True" ItemsSource="{Binding InventoryItemNames}" SelectedItem="{Binding Name}" />
                                    </Grid>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellEditingTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Header="{LocText Quantity}"
                                     CellStyle="{StaticResource RightAlignedGridCell}">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Margin="3" Text="{Binding Path=Quantity,StringFormat='#,#0.##'}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                            <DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <Grid FocusManager.FocusedElement="{Binding ElementName=tb}">
                                        <Common:FilteredTextBox Type="Number" Text="{Binding Path=Quantity,StringFormat='#,##.##'}"
                                                     Name="tb" />
                                    </Grid>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellEditingTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn Header="{LocText Unit}"
                                     IsReadOnly="True" CellStyle="{StaticResource LeftAlignedGridCell}">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Margin="3" Text="{Binding Path=UnitName,StringFormat='#,#0.##'}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                    <DataGrid.ContextMenu>
                        <ContextMenu>
                            <MenuItem Command="{Binding AddInventoryItemCommand}" Header="{Binding AddInventoryItemCommand.Caption}" />
                            <MenuItem Command="{Binding DeleteInventoryItemCommand}" Header="{Binding DeleteInventoryItemCommand.Caption}" />
                        </ContextMenu>
                    </DataGrid.ContextMenu>
                </DataGrid>
                <StackPanel Margin="10">
                    <TextBlock Margin="2,3">
                                <Hyperlink Command="{Binding AddInventoryItemCommand}">
                                    <TextBlock Text="{Binding Path=AddInventoryItemCommand.Caption}" />
                                </Hyperlink>
                            </TextBlock>
                    <TextBlock Margin="2,3">
                                <Hyperlink Command="{Binding DeleteInventoryItemCommand}">
                                    <TextBlock Text="{Binding Path=DeleteInventoryItemCommand.Caption}" />
                                </Hyperlink>
                            </TextBlock>
                </StackPanel>
            </StackPanel>
        </GroupBox>
        
        <StackPanel Grid.Row="2">
            <Button HorizontalAlignment="Left" Margin="0,10" MinWidth="70" Content="{Binding SaveCommand.Caption}"
                 Command="{Binding SaveCommand}" />
            <Label Content="{Binding Error}" Foreground="Red" />
        </StackPanel>
    </Grid>
</UserControl>